<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Reference extends CI_Controller {
	
	private $tab = 'user';
	private $sub = '';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	private function invite_data($limit = false){
		$per_page  = intval($this->input->get('per_page'));
		$page_size = 10;
		$parms     = array(
			'username'   => trim($this->input->get('username')),
			'invite_username'   => trim($this->input->get('invite_username')),
		);
		
		$this->load->model('User_model', 'user');
		
		if($limit && $limit='all'){
			$data = array('limit'=>'all');
		}else{
			$data = array('per_page'=>$per_page,'page_size'=>$page_size);
		}
		$vdata = $this->user->invite_list($parms,$data);
		$vdata['parms'] = $parms;
		return $vdata;
	}

	function index(){
		
		$vdata = $this->invite_data();
		$parms = $vdata['parms'];
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/reference?username='.$parms['username'].'&invite_username='.$parms['invite_username'];
		$config['total_rows'] = $vdata['user_count'];
		$config['per_page'] = 10; 
		$this->pagination->initialize($config); 
		$vdata['title'] = '推荐列表';
		
		
		
		$vdata['tab'] = $this->sub;
		$vdata['sub'] = 'invite';
		
		$this->load->view('/sys_admin/user/invite_list', $vdata);
	}
	
	
	function invite_excel(){
		$vdata = $this->invite_data('all');
		
		$this->load->library('PHPExcel');
		$this->load->library('PHPExcel/IOFactory'); 
		
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("推荐信息")->setDescription(COMPANY_NAME); 
		
		$objPHPExcel->setActiveSheetIndex(0);
		$titles = array("编号", "推荐人", "投资人", "投资总金额", "投资总笔数");
		
		for($i = 0; $i < count($titles); $i ++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $titles[$i]);
		}
				
		$user_list = $vdata['user_list'];
		
		
		for($i = 0; $i < count($user_list); $i++){	
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $i+2, $user_list[$i]['user_id']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $i+2, $user_list[$i]['invite_username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $i+2, $user_list[$i]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $i+2, $user_list[$i]['money']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $i+2, $user_list[$i]['count']);
		}
		
		$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); 
		header('Content-Type: application/vnd.ms-excel'); 
		header('Content-Disposition: attachment;filename="推荐信息.xls"'); 
		header('Cache-Control: max-age=0'); 
		$objWriter->save('php://output'); 
		exit;
	}

=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Reference extends CI_Controller {
    
	private $tab = 'user';
	private $sub = '';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	private function invite_data($limit = false){
		$per_page  = intval($this->input->get('per_page'));
		$page_size = 10;
		$parms     = array(
			'username'   => trim($this->input->get('username')),
			'invite_username'   => trim($this->input->get('invite_username')),
		);
		
		$this->load->model('User_model', 'user');
		
		if($limit && $limit='all'){
			$data = array('limit'=>'all');
		}else{
			$data = array('per_page'=>$per_page,'page_size'=>$page_size);
		}
		$vdata = $this->user->invite_list($parms,$data);
		$vdata['parms'] = $parms;
		return $vdata;
	}

	function index(){
		
		$vdata = $this->invite_data();
		$parms = $vdata['parms'];
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/reference?username='.$parms['username'].'&invite_username='.$parms['invite_username'];
		$config['total_rows'] = $vdata['user_count'];
		$config['per_page'] = 10; 
		$this->pagination->initialize($config); 
		$vdata['title'] = '推荐列表';
		
		
		
		$vdata['tab'] = $this->sub;
		$vdata['sub'] = 'invite';
		
		$this->load->view('/sys_admin/user/invite_list', $vdata);
	}
	
	
	function invite_excel(){
		$vdata = $this->invite_data('all');
		
		$this->load->library('PHPExcel');
		$this->load->library('PHPExcel/IOFactory'); 
		
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("推荐信息")->setDescription(COMPANY_NAME); 
		
		$objPHPExcel->setActiveSheetIndex(0);
		$titles = array("编号", "推荐人", "投资人", "投资总金额", "投资总笔数");
		
		for($i = 0; $i < count($titles); $i ++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $titles[$i]);
		}
				
		$user_list = $vdata['user_list'];
		
		
		for($i = 0; $i < count($user_list); $i++){	
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $i+2, $user_list[$i]['user_id']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $i+2, $user_list[$i]['invite_username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $i+2, $user_list[$i]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $i+2, $user_list[$i]['money']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $i+2, $user_list[$i]['count']);
		}
		
		$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); 
		header('Content-Type: application/vnd.ms-excel'); 
		header('Content-Disposition: attachment;filename="推荐信息.xls"'); 
		header('Cache-Control: max-age=0'); 
		$objWriter->save('php://output'); 
		exit;
	}

>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}